
#include "Tcpserver.hpp"
#include "Common.hpp"
#include "Protocol.hpp"
#include "Cal.hpp"
#include "Dameo.hpp"


int main(int argc,char* argv[])
{
    if(argc!=2)
    {
        std::cerr<<"usage :"<<argv[0]<<"port"<<std::endl;
        exit(USAGE_ERR);
    }
    //Daemon();
    daemon(1,1);
    //业务模块
    //完成计算功能
    std::unique_ptr<Cal> cal=std::make_unique<Cal>();

    //协议模块
    std::unique_ptr<Protocol> protocol=std::make_unique<Protocol>(
        [&cal](Request& req)->Response
        {
            return cal->Execute(req);
        }
    );    
    
    //网络通信功能
    std::unique_ptr<Tcpserver> tsvr=std::make_unique<Tcpserver>(std::stoi(argv[1]),
        [&protocol](std::shared_ptr<Socket>& sock,InetAddr& client)
    {
        protocol->GetRequest(sock,client);
    });
    tsvr->start();
    return 0;
}